#!/bin/bash
#This script was written by Matthew Vona of ARB to support the CarbLogger 
#project 6/6/2011 for Ubuntu 11.04 using network manager to connect via
#a wireless broadband router. The script requires that networkmanager can use
#the connection, and is available as a droptown from the desktop applet.
usage()
{
echo "Proper usage is $0 <connection name>"
}

#USER CONFIGURATION:
#CON_NAME is the name of the connection you want to use.
CON_NAME=$1;
#USE OPTIONAL TO RUN COMMANDS AFTER CONNECTION IS RE-ESTABLISHED
#IN THIS CASE WE WANT TO UPDATE DYNAMIC DNS WITH OUT CURRENT IP
OPTIONAL="ddclient"
if [ $# != "1" ]; then
{
usage
exit 1
}
fi 
CONNECTED=`nmcli con status id $CON_NAME | wc -l`
while [ $CONNECTED -lt 2 ]
do
	nmcli con up id $CON_NAME
	sleep 15
	CONNECTED=`nmcli con status id $CON_NAME | wc -l`
done
$OPTIONAL
exit